<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="ui" uri="http://com.am.tag" %>
<%@ include file="../common.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'userList.jsp' starting page</title>
    <script type="text/javascript" src="${path}/js/public/grid.js"></script>
	<script type="text/javascript">
		function sexRender(value ,record,columnObj,grid,colNo,rowNo)
		{
			if(value == "0")
			{
				return "男";	
			}
			if(value == "1")
			{
				return "女";	
			}
		}
		
		function doSave()
  		{
  			openDailog("view","${path}/jsp/user/userEdit.jsp",510,270,"添加用户",false,true,null,function(dlg){
  				
  				dlg.getIFrame().doSave();
  			});
  		}
		
		function doEdit()
  		{
			
			if(!isSelectOne(mygrid))
			{
				alert("请选择一条记录进行修改");
				return;
			}
			var record = mygrid.getSelectedRecords()[0];
			openDailog("view","${path}/jsp/user/userEdit.jsp?id=" + record['id'],510,270,"修改用户",false,true,null,function(dlg){
  				dlg.getIFrame().doSave();
  			});
  		}
		
		function doDelete()
		{
			if(!isSelectOne(mygrid))
			{
				alert("请选择一条记录进行删除");
				return;
			}
			
			if(confirm("你是否确定要删除此记录"))
  			{
				var id = mygrid.getSelectedRecords()[0].id + "";
				ajax.remoteCall("com.system.dao.UserDao:delete",[id],function(reply){
  	    			var result = reply.getResult();
  	    			alert(result.value);
  	    			if(result.type == "success")
  	    			{
  	    				mygrid.reload();
  	    			}
  	    		});
  			}
		}
  		
  		function initPassword(id)
  		{
  			if(confirm("你确定要初始化此用户的密码?"))
  			{
  				ajax.remoteCall("com.system.dao.UserDao:initPassword",[id+""],function(reply){
  	    			var result = reply.getResult();
  	    			alert(result.value);
  	    		});
  			}
  		}
  		
  		function oprtRender(value,record,columnObj,grid,colNo,rowNo)
  		{
  			return "<a href='javascript:void(0)' style='text-decoration: none;'  onclick='initPassword(" + grid.getColumnValue('id',rowNo) + ")'>重置密码</a>";
  		}
  		
  		function doQuery()
  		{
  			resetGrid(mygrid,"queryForm");
  		}
  		
  		function doExport()
  		{
  			$.gridToXls(mygrid,"com.system.provider.UserListProvider","用户列表.xls","id，oprt");
  		}
  		
  		function campusRender(value)
  		{
  			if(value == "0")
			{
				return "校本部";	
			}else if(value == "1")
			{
				return "白云校区";	
			}else if(value == "2")
			{
				return "北校区";	
			}else{
				return "西校区";	
			}
  		}
	</script>
  </head>
  
  <body style="overflow: hidden;">
  
  	<table cellSpacing="0" cellPadding="0" style="width:100%;height:100%;" border="0">
  		<tr>
			<td class="windowTitle">系统管理  &gt; 用户管理</td>
		</tr>
  		<tr id="">
  			<td style="height:35px;width:100%" class="windowHead">	
	  			<form id="queryForm">
					<table cellSpacing="0" cellPadding="0" width="100%" height="100%" border="0" >
						<tr>
							<td>	
								<ui:Permission value="user_add">
									<ui:Button type="save" onclick="doSave()">新增</ui:Button>
								</ui:Permission>
								<ui:Permission value="user__modify">
									<ui:Button type="edit" onclick="doEdit()">修改</ui:Button>
								</ui:Permission>
								<ui:Permission value="user_delete">
									<ui:Button type="delete" onclick="doDelete()">删除</ui:Button>
								</ui:Permission>
								<ui:Permission value="user_emport">
									<ui:Button type="export" onclick="doExport()">导出</ui:Button>
								</ui:Permission>
							</td>
						</tr>
						<tr>
						</tr>
					</table>
				</form>
				<br/>
				<a style="text-decoration: none;"></a>
			</td>
		</tr>
		
		<tr>
			<td style="width:100%;height:100%;overflow:hidden"  class="windowBody">
				<div id="mess_box" style="width:100%;height:100%;overflow:hidden">
					<ui:Grid id="mygrid" css="width:100%;height:100%"
				    		 onCellClicked="selectedSingleRow2"
				    		 dataProvider="com.system.provider.UserListProvider:getData" >
				    	<ui:GridField name="id" header="ID" isChecked="true" align="center"/>
				    	<ui:GridField name="name" header="姓名" align="center" width="20%"/>
				    	<ui:GridField name="oprt" header="操作" align="center" width="10%" render="oprtRender"/>
				    	<ui:GridField name="sex" header="性别" align="center" width="12%" render="sexRender"/>
				    	<ui:GridField name="telephone" header="联系电话" align="center" width="25%"/>
				    	<ui:GridField name="campus" header="所属校区" align="center" width="30%" render="campusRender"/>
			    	</ui:Grid>
		    	</div>
		    </td>
		</tr>
  	</table>
  	<script type="text/javascript">
		$().ready(function(){
			disableSelectAll(mygrid);
		});
	</script>
  </body>
</html>
